package com.draven.mall.dispatch;

import com.draven.mall.entity.Order;
import com.draven.mall.entity.Rider;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Random;

/**
 * 随机分配算法实现
 * 从可用骑手中随机选择一个进行分配
 */
@Component
public class RandomDispatchAlgorithm implements DispatchAlgorithm {

    private final Random random = new Random();

    @Override
    public Rider assignRider(Order order, List<Rider> availableRiders) {
        if (availableRiders == null || availableRiders.isEmpty()) {
            return null;
        }
        
        // 随机选择一个骑手
        int index = random.nextInt(availableRiders.size());
        return availableRiders.get(index);
    }

    @Override
    public int getType() {
        return 1; // 算法类型：1-随机分配
    }

    @Override
    public String getName() {
        return "随机分配";
    }
} 